<template>
     <div class="shoping" >
         <div v-for="(item,index) in products" :item='item' :key='index'>
            <!-- <router-link :to="`/list?id=${item.id}&name=${item.name}`"> -->
            <router-link :to="{
                name:'detail',
                params:{
                    id:item.id,
                    name:item.name,
                    price:item.price,
                    img:item.img,
                    num:item.num
                }
            }">
                <div class="ym">
                    <img :src="item.img" alt="">
                    <h4>{{item.name}}</h4><br>
                    <div class="a"><span class="count">{{item.num}}</span><span>折起</span></div>
                </div>
            </router-link>
         </div>
         <router-view></router-view>
     </div>
 
</template>

<script>
import product from '../data/product'
import ConstName from '../config/constName';
export default {
  name: 'AdvList',
  data(){
      return {
          products:[],
          num:1
      }
  },
  mounted:function(){
      console.log(this)
      this.products=product.products;
      //绑定消减库存的方法
      this.public.$on(ConstName.reduceNum,(id,num)=>{
           console.log('收到了消息，现在就去减库存')
           console.log(id,num)
      });
      
  },
  beforeCreate:function(){
      console.log('销毁了');
      // 销毁的时候，建议把全局事件移动掉
      //this.public.$off(ConstName.reduceNum)
      //this.public.$off([])// 移除所有绑定事件

  }
}
</script>
<style scoped>
 .shoping {
     margin:0 5%;
 }
 .ym {
     width: 420px;
     height: 285px;
     background-color: #fff;
     margin-bottom: 20px;
     border-radius: 6px;
 }
 img {
     border-radius: 6px 6px 0px 0px;
     width: 420px;
 }
 .count {
     color: #E04F9F;
 }
 h4 {
     margin: 12px 40px -8px 20px;
 }
.a {
    margin-left: 20px;
    color: #7C7F92;
    font-size: 15px;
    padding-bottom: 10px;
    margin-bottom: 10px;
 }
</style>
